package org.ponly.uno4j.util;

import org.ponly.uno4j.core.UnoClient;
import org.ponly.uno4j.support.D2sSupport;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * 文档转换为 SWF 样例, 此程序仅作为样例使用, 请勿作为生产使用
 *
 * @author vacoor
 */
public class D2s extends D2sSupport {
    private UnoClient unoClient;
    private ExecutorService p2sExecutor;

    public D2s(UnoClient unoClient, int pdf2swfMaxProcess) {
        this(unoClient, Executors.newFixedThreadPool(pdf2swfMaxProcess));
    }

    public D2s(UnoClient unoClient, ExecutorService p2sExecutor) {
        this.unoClient = unoClient;
        this.p2sExecutor = p2sExecutor;
    }

    @Override
    public Future<?> submit(File source, File swf) throws FileNotFoundException {
        return super.submit(source, swf);
    }

    @Override
    protected UnoClient getUnoClient() {
        return unoClient;
    }

    @Override
    protected void doExecutePdfToSwfTask(FutureTask<?> pdfToSwfTask) {
        p2sExecutor.submit(pdfToSwfTask);
    }

    public void shutdown() {
        p2sExecutor.shutdown();
        unoClient.shutdown();
    }
}
